module.exports = function ($scope, $state, $resource, $modal, toaster, date2str, str2date) {
  $scope.myKeyup = function (e) {
		//IE 编码包含在window.event.keyCode中，Firefox或Safari 包含在event.which中
		var keycode = window.event ? e.keyCode : e.which;
		if (keycode == 13) {
			$scope.loadlist();
		}
  };
  $scope.vm = {
      'date' : '',
      'options' : {
          format: "YYYY-MM-DD",
          locale : 'zh-cn'
      }
  }
  $scope.vm1 = {
      'date' : '',
      'options' : {
          format: "YYYY-MM-DD",
          locale : 'zh-cn'
      }
  }
	/* 分页
   * ========================================= */
  $scope.maxSize = 5;            //最多显示多少个按钮
  $scope.bigCurrentPage = 1;      //当前页码
  $scope.itemsPerPage = 10; 
  $scope.searchform = {};
	$scope.loadlist = function () {
    console.log($scope.vm.date._d, $scope.vm1.date._d)
    if ($scope.vm.date._d == undefined || $scope.vm1.date._d == undefined) {
      $scope.vm.date = '';
      $scope.vm1.date = '';
      $scope.searchform.start_time = $scope.vm.date;
      $scope.searchform.end_time = $scope.vm1.date;
      console.log($scope.vm.date);
    } else {
      $scope.vm.date._d = date2str($scope.vm.date._d);
      $scope.vm1.date._d = date2str($scope.vm1.date._d);
      $scope.searchform.start_time = $scope.vm.date._d;
      $scope.searchform.end_time = $scope.vm1.date._d;
    }
    // if ( $scope.vm.date._d === null) {
    //   $scope.vm.date._d = '';
    // }
    // if (typeof $scope.vm.date._d === 'string') {
    //     $scope.vm.date._d = $scope.vm.date._d;
    // } else {
    //     $scope.vm.date._d = date2str($scope.vm.date._d);
    // }
    // if ($scope.vm1.date._d == undefined) {
    //   $scope.vm1.date = '';
    // }
    // if ( $scope.vm1.date._d === null) {
    //   $scope.vm1.date._d = '';
    // } else 
    // if (typeof $scope.vm1.date._d === 'string') {
    //     $scope.vm1.date._d = $scope.vm1.date._d;
    // } else {
    //     $scope.vm1.date._d = date2str($scope.vm1.date._d);
    // }
    var para = {
        pageNo:$scope.bigCurrentPage, 
        pageSize:$scope.itemsPerPage,
        asort:'desc',
    };
    para = angular.extend($scope.searchform, para);
		$resource('/api/as/mc/userfans/findAllFansByTimeList', {}, {}).save(para, function (res) {
			if (res.errcode === 0) {
        $scope.objs = res.data.results;
        $scope.bigTotalItems = res.data.totalRecord;
			} else {
				toaster.error({ title: '', body: res.errmsg });
			}
		});
	}

	$scope.loadlist();

	//查看下集
	$scope.seeLevel = function (obj) {
      console.log(obj.wxuid);
      $state.go('app.skwxShopOrderList', {'wxuid' : obj.wxuid});
  }
  // 邀请分销商
  var qrcode = '';
  var url = '';
  console.log(window.location.host);
  if (window.location.host == 'https://tsv.juyouhx.com'){
    url = 'https://weixint.juyouhx.com/views//distributor/apply_distributor.html?cid='
  } else {
    url = 'https://dlqt.juyouhx.com/skv4/views/distributor/apply_distributor.html?cid='
  }
  var cid = '';
  var pwx = 0;
  $resource('/api/ac/mc/merchantUserShopService/getcid', {}, {}).save({}, function (res) {
    if (res.errcode === 0) {
      console.log(res.data);
      cid = res.data.cid;
      qrcode = url + cid + '&' + pwx;
      console.log('qrcode' + qrcode);
    } else {
      toaster.error({ title: '', body: res.errmsg });
    }
  });
  $scope.add = function (){
        var modalInstance = $modal.open({
          template: require('../views/skwxOrcode1.html'),
          controller: 'skwxOrcode1',
          size: 'sm',
          resolve: {
            qrcode: function () {
              return qrcode;
            }
          }
        });
        modalInstance.result.then(function () {
          $scope.loadlist();
        });
  }

};